<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <div class="contentsize">经营分析月报历史数据</div>
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-form ref="form" :model="form" label-width="80px" :inline="true" size="mini">
                    <el-form-item label="日期:">
                        <el-date-picker v-model="time" type="month" placeholder="选择月" @change="changeTime" value-format="yyyy-M"> </el-date-picker>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSearch" icon="el-icon-search" class="searchcolor" style="margin-left: 10px"
                            >查询</el-button
                        >
                        <el-button @click="reSearch" icon="el-icon-refresh" class="searchcolor">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <el-table
                :data="tableData"
                style="width: 100%"
                :header-cell-style="tableHeaderColor"
                :row-style="tablerowColor"
                :row-class-name="tableRowClassName"
                :cell-style="tablecellColor"
                border
                :max-height="maxHeight"
            >
                <el-table-column prop="year" label="年" align="center"></el-table-column>
                <el-table-column prop="month" label="月" align="center"></el-table-column>
                <el-table-column label="操作" width="100" align="center" fixed="right">
                    <template slot-scope="scope">
                    <el-button type="text" size="small" @click="goYbDetails(scope.row)">查看</el-button>
                </template>
                </el-table-column>
            </el-table>
            <div class="pagination" style="float: right">
                <el-pagination
                    background
                    layout="total,sizes,prev, pager, next,jumper"
                    :total="total"
                    :current-page.sync="current"
                    :page-size="pageSize"
                    @current-change="handleCurrentChange"
                    :page-sizes="[10, 20, 30, 40, 50, 100]"
                    @size-change="handleSizeChange"
                >
                </el-pagination>
            </div>
        </div>
    </div>
</template>
<script>
import { jyyblslist } from '@/api/index';
export default {
    name: 'dalist',
    data() {
        return {
            time:'',
            total: 0,
            current: 1,
            pageSize: 10,
            form: {
                current:1,
                pageSize:10,
                year: '',
                month:'',
                type: this.$store.getters.type
            },
            tableData: [{year:'2025',month:'3'}],
            maxHeight: null,
            type: this.$store.getters.type
        };
    },
    components: {},
    computed: {},
    methods: {
        // 列表样式
        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex === 0) {
                return 'background:linear-gradient(to bottom, #008A94,#0ae2f2)!important;color:#ffffff;font-size:14px;';
            }
        },
        tablerowColor({ row, rowIndex }) {
            return 'height: 42px;font-size:14px;color:black';
        },
        tablecellColor() {
            return 'font-weight:700;color:#000000;border-color:#c0c0c0';
        },
        tableRowClassName({ row, rowIndex }) {
            if (rowIndex % 2 != 0) {
                return 'success-row'; //这是类名
            } else {
                return '';
            }
        },
        // 换页
        handleCurrentChange(val) {
            this.current = val;
            this.form.current = val;
            this.form.pageSize = this.pageSize;
            this.jyyblslist(this.form);
            console.log(val);
        },
        // 每页条数
        handleSizeChange(val) {
            this.current = 1;
            this.pageSize = val;
            this.form.pageSize = val;
            this.jyyblslist(this.form);
            console.log(val);
        },
        // 搜索
        onSearch() {
            this.current = 1;
            this.form.current = 1;
            this.form.year=this.time?this.time.split('-')[0]:''
            this.form.month=this.time?this.time.split('-')[1]:''
            this.jyyblslist(this.form);
            console.log('搜索');
        },
        // 重置
        reSearch() {
            this.current = 1;
            this.pageSize = 10;
            this.form = {};
            this.jyyblslist(this.form);
            console.log('搜索');
        },
        // 删除
        deleteClick(e) {
            console.log(e);
            this.$confirm('确定删除此条信息吗？')
                .then(() => {
                    let data = { id: e.id };
                    projectdelete(data).then((res) => {
                        if (res.code == 200) {
                            this.jyyblslist(this.form);
                            this.$message.success('删除成功');
                        }
                    });
                })
                .catch(() => {
                    this.$message.success('删除取消');
                });
        },
        // 项目列表
        jyyblslist(data) {
            jyyblslist(data).then((res) => {
                if (res.code == 200) {
                    this.tableData = res.data.records;
                    this.total = res.data.total;
                } else {
                    this.tableData = [];
                    this.total = 0;
                }
            });
        },
        // 改变时间事件
        changeTime() {
            console.log(this.time);
            this.form.year=this.time.split('-')[0]
            this.form.month=this.time.split('-')[1]
            console.log(this.form)
        },
        goYbDetails(e){
            this.$router.push({
                    // name: val,
                    name: 'jlbtj',
                    params: {
                        ...e,
                        type: this.$store.getters.type
                    }
                });
        }
    },
    mounted() {
        this.$nextTick(() => {
            // window.innerHeight 浏览器窗口的可见高度，下面的 420 是除了table最大高度的剩余空间。
            this.maxHeight = window.innerHeight - 440;
            this.jyyblslist(this.form);
        });
    }
};
</script>

<style scoped>
.container {
    /* height: calc(100vh - 260px); */
    overflow: hidden;
}

.crumbs {
    background-color: #fff;
    padding: 20px 20px;
}

.indexTitle {
    margin-bottom: 20px;
}

.contentsize {
    font-size: 18px;
    font-weight: 700;
}

.handle-box {
    overflow: hidden;
}

/* 新增按钮 */
.addcolor {
    margin-bottom: 10px;
}
</style>
<style>
.success-row {
    background-color: #eaf3fb !important;
}
</style>
